package com.queue;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;

public class MyStack {

    public static void main(String[] args) {
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);

        /*System.out.println(stack.peek());
        stack.pop();
        System.out.println(stack.peek());
        stack.pop();
        System.out.println(stack.peek());
        stack.pop();*/
    }

    Queue<Integer> q1 = new LinkedList<>();
    Queue<Integer> q2 = new LinkedList<>();

    public void push(int x){
        q2.add(x);
        while (!q1.isEmpty()){
            q2.add(q1.poll());
        }

        Queue<Integer> q = q1;
        q1 = q2;
        q2 = q;

        System.out.println(Arrays.toString(q1.toArray()));
        System.out.println(Arrays.toString(q2.toArray()));
    }

    public int pop(){
        if (q1.isEmpty()) return -1;
        return q1.poll();
    }

    public int peek(){
        if (q1.isEmpty()) return -1;
        return q1.peek();
    }
}
